package org.theSeed.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.theSeed.base.pojo.constant.SysConstant;
import org.theSeed.pojo.dto.UserInfo;
import org.theSeed.pojo.dto.UserInfoUserDetails;

import java.util.Arrays;

@Component
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername("test");
        //密码为test
        userInfo.setPassword("$2a$10$ssXtJxQm5GvrM8JK0bKWY.wlRgl07Ybk3QFEvS4V4vSWllnk8S1Iy");
        userInfo.setLockFlag(SysConstant.ZERO);
        userInfo.setEnableFlag(SysConstant.ONE);
        userInfo.setRoleCodeList(Arrays.asList("admin"));
        return new UserInfoUserDetails(userInfo);
    }
}
